<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>全球疫情实时更新</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo"><strong>全球疫情实时更新</strong></div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item layui-this"><a href="index">国内</a></li>
                <li class="layui-nav-item"><a href="color/index">国内疫情分布图</a></li>
                <li class="layui-nav-item"><a href="foreign">国外</a></li>
                <li class="layui-nav-item"><a href="color">全球对比图</a></li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <div style="padding: 15px;">
            <div class="demoTable">
                搜索城市：
                <div class="layui-inline">
                    <input class="layui-input" name="id" id="demoReload" autocomplete="off">
                </div>
                <button class="layui-btn" id="btn" data-type="reload">搜索</button>
            </div>
            <table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>
        </div>
    </div>
</div>
<script src="../layui/layui.js"></script>
<script>
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;

    });

    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#LAY_table_user'
            ,url:'/data/china'
            ,cellMinWidth: 80
            ,cols: [
                [
                    {field:'state', title: '城市'}
                    ,{field:'country', title: '国家'}
                    ,{field:'latestTotalCase', title: '最新感染总人数', sort: true, align: 'center'}
                    ,{field:'diffFromPrevDay', title: '相较前一天感染人数', sort: true, align: 'center'}
                ]
            ]
            ,id: 'testReload'
        });
        var $ = layui.$, active = {
            reload: function(){
                var demoReload = $('#demoReload');
                console.log("key:" + demoReload.val());
                //执行重载
                table.reload('testReload', {
                        url: '/data/city'
                        ,where: {
                            state: demoReload.val()
                        }
                    }
                );
            }
        };
        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>